package com.ruoyi.system.domain;

import com.alibaba.fastjson2.JSONArray;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.ruoyi.common.core.domain.FileObject;
import com.ruoyi.common.enums.comlbs.StsListEnum;
import com.ruoyi.system.domain.vo.common.DeviceGps;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 实时定位
 *
 * @author zscat
 * @email 163@qq.com
 * @date 2021-01-07 14:43:48
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
@Accessors(chain = true)
public class RealtimePositioning implements Serializable {
    //ID
    private Long id;
    //所属作业公司id
    private Long companyId;
    //所属作业公司名称
    private String companyName;
    //备注（公司）
    private String remark;
    //车辆id
    private Long vehicleId;
    //车牌号
    private String numberPlate;
    //用户姓名
    private String name;
    //设备id
    private Long equipmentId;
    //设备编号
    private String deviceId;
    //经度
    private String lng;
    //纬度
    private String lat;
    //地址
    private String location;
    //卫星定位数
    private Integer satelliteCount;
    //设备类型  0：车载设备 1：人体佩戴设备
    private Integer equipmentType;
    //驾驶员
    private String driver;
    //当前时间
    private String gpsDateTime;
    //行驶速度
    @JsonProperty("spd")
    private Integer speed;
    //父节点
    private Long parentId;
    //车辆状态
    private String vehicleStatus;
    //车辆图片url数组
    private List<FileObject> vehiclePic;
    //监管类型
    private Integer objType;
    private String objTypeName;
    //图标
    private String objIcon;
    //节点类型
    private Integer type = 2;
    //车辆里程
    private Double mileage;
    //车辆颜色
    private String vehicleColor;
    //车辆品牌
    private String vehicleBrand;
    //车辆型号
    private String vehicleModel;
    //驾驶员姓名
    private String driverName;
    //公司地址
    private String companyAddress;
    //公司简称
    private String companyShortName;
    //公司负责人
    private String companyPerson;
    //公司电话
    private String companyNumber;
    //acc
    private Integer acc;
    //左转
    private Integer turnLeft;
    //右转
    private Integer turnRight;
    //远光灯
    private Integer highBeam;
    //近光灯
    private Integer dippedHeadlight;
    //油路
    private Integer oil;
    //刹车
    private Integer brake;
    //上级公司
    private String parentName;
    //设备型号
    private Integer deviceModel;
    //Sim卡号
    private String simId;
    //设备型号名称
    private String deviceModelStr;
    //设备型号名称
    private String equipmentTypeStr;
    //车辆型号名称
    private String vehicleModelStr;
    //通道号
    private String channelsNum;
    //里程KM
    private Double kilometer;

    private Double dayKMeter;

    //信号强度（百分比）
    private Integer signalIntensity;

    // 以下为北三字段
    //发送方id
    private Long sendId;
    //接收方id
    private Long receiveId;
    //定位状态
    private String locationState;
    //短报文类型
    private String shortMsgType;
    //短报文内容
    private String shortMsg;
    //传感器数组
    private JSONArray sensorList = new JSONArray();
    //高程
    private Integer hgt;

    /**
     * 大数据定位数据设置
     * @param gps
     */
    public void updateGpsData(DeviceGps gps){
        setLat(gps.getLat().toString());
        setLng(gps.getLng().toString());
        setGpsDateTime(gps.getGdt());
        setSpeed(gps.getSpd());
        setLocation(gps.getLocation());
        setMileage(gps.getMie().doubleValue());
        setKilometer(gps.getKilometer());
        setDayKMeter(gps.getDayKMeter());
        if (getVehiclePic() == null) setVehiclePic(new ArrayList<>());
    }

    /**
     * 基础数据设置
     * @param detail
     */
    public void updateBaseData(RealtimePositioning detail){
        setCompanyName(detail.getCompanyName());
        setCompanyAddress(detail.getCompanyAddress());
        setCompanyNumber(detail.getCompanyNumber());
        setCompanyPerson(detail.getCompanyPerson());
        setCompanyShortName(detail.getCompanyShortName());
        setVehicleBrand(detail.getVehicleBrand());
        setVehicleColor(detail.getVehicleColor());
        setVehicleModel(detail.getVehicleModel());
        setDriver(detail.getDriverName());
        setSimId(detail.getSimId());
        setChannelsNum(detail.getChannelsNum());
        setVehicleModelStr(detail.getVehicleModel());
        setObjIcon(detail.getObjIcon());
        setObjType(detail.getObjType());
    }

    /**
     * 更新Sts数据
     * @param stsList
     */
    public void updateStsData(List<Integer> stsList){
        //acc开关
        if (stsList.contains(StsListEnum.Acc.getCode())) {
            setAcc(StsListEnum.Acc.getCode());
        }
        //油路
        if (stsList.contains(StsListEnum.OilLine.getCode())) {
            setOil(StsListEnum.OilLine.getCode());
        }
        //刹车
        if (stsList.contains(StsListEnum.Breaking.getCode())) {
            setBrake(StsListEnum.Breaking.getCode());
        }
        //左转
        if (stsList.contains(StsListEnum.LeftTurn.getCode())) {
            setTurnLeft(StsListEnum.LeftTurn.getCode());
        }
        //右转
        if (stsList.contains(StsListEnum.RightTurn.getCode())) {
            setTurnRight(StsListEnum.RightTurn.getCode());
        }
        //远光灯
        if (stsList.contains(StsListEnum.DistanceLight.getCode())) {
            setHighBeam(StsListEnum.DistanceLight.getCode());
        }
        //近光灯
        if (stsList.contains(StsListEnum.LowLight.getCode())) {
            setDippedHeadlight(StsListEnum.LowLight.getCode());
        }
    }
}
